﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Timer : MonoBehaviour
{
	public Text timerText; //4、显示计时的界面
	public float time = 30.0f; //4、游戏时间
	private bool canCountDown = false; //4、判断是否可以计时

	// Start is called before the first frame update
	void Start()
	{
	}

	// Update is called once per frame
	void Update()
	{
		if (canCountDown == true)
		{
			//4、判断是否可以计时
			time -= Time.deltaTime;
			//4、开始计时
			timerText.text = "Time: " + time.ToString("F1");
			//4、在 UI 上显示计时信息
			//Debug.Log(time);
		}
	}
	public void CountDown(bool countDown)
	{
		//4、用于设置是否开始倒计时
		this.canCountDown = countDown;

		if (canCountDown == false)
		{
			//6、计时归零
			time = 0;
			timerText.text = "Game Over!!!";
		}
	}

}
